<!--
  - Copyright (C) 2024
  - All rights reserved, Designed By www.joolun.com
  - 注意：
  - 本软件为www.joolun.com开发研制，未经购买不得使用
  - 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
  - 一经发现盗用、分享等行为，将追究法律责任，后果自负
-->
<!-- 直播设置 -->
<template>
	<view>
		<view class="live-set-btn" :style="{ top: sysInfo.safeArea?.top + 20 + 'px' }" @tap="onShowSet"><text class="text">设置</text></view>
		<view v-if="modalShow" :class="['live-set-box', { 'show-box': modalShow }]">
			<uni-transition
				mode-class="slide-top"
				:styles="{ width: boxWidth + 'px', height: boxHeight + 'px', backgroundColor: '#ffffff', position: 'fixed', top: 0, zIndex: 999 }"
				:show="modalShow"
				:duration="500"
			>
				<view class="live-set">
					<view class="live-set-title">
						<text class="title">摄像头设置</text>
						<image @tap="hideModalShow" class="close-icon" src="/package-live/static/img/icon_close.png" />
					</view>
					<view class="live-set-content">
						<view class="live-set-item">
							<text class="title">摄像头</text>
							<text @tap="onSwitchCamera" class="btn-box">切换摄像头</text>
						</view>
					</view>
				</view>
			</uni-transition>
			<view v-if="modalShow" class="modal-show-cancel" @tap="hideModalShow" />
		</view>
	</view>
</template>

<script>
export default {
	props: {
		livePusherCtx: [Object],
		sysInfo: {
			type: Object,
			default() {
				return {};
			}
		}
	},
	data() {
		return {
			modalShow: false,
			boxWidth: 0,
			boxHeight: 0
		};
	},
	mounted() {
		this.initView();
	},
	methods: {
		initView() {
			this.boxWidth = this.sysInfo.windowWidth;
			this.boxHeight = '120';
			// this.boxHeight = sysInfo.windowHeight * 0.7;
		},
		onShowSet(value) {
			this.modalShow = true;
		},
		hideModalShow() {
			this.modalShow = false;
		},
		onSwitchCamera() {
			if (this.livePusherCtx) {
				// https://uniapp.dcloud.net.cn/api/media/live-pusher-context.html#switchcamera
				this.livePusherCtx.switchCamera({
					success: () => {},
					fail: () => {}
				});
			}
		}
	}
};
</script>
<style lang="scss" scoped>
.live-set-btn {
	height: 32rpx;
	position: fixed;
	right: 30rpx;
	top: 20rpx;
	.text {
		color: #ffffff;
		font-size: 14px;
	}
}
.live-set-box {
	z-index: -1;
	position: fixed;
	flex: 1;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	&.show-box {
		z-index: 999;
	}
	.modal-show-cancel {
		z-index: 110;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.4);
	}
	// 直播商品
	.live-set {
		.live-set-title {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			margin-top: 40rpx;
			.title {
				flex: 1;
				display: flex;
				font-size: 32rpx;
				height: 93rpx;
				line-height: 93rpx;
				font-weight: bold;
				padding: 0 24rpx;
			}
			.close-icon {
				background-color: rgba(0, 0, 0, 0.4);
				width: 45rpx;
				height: 45rpx;
				margin: 5px;
			}
		}
		.live-set-content {
			padding: 0px 10px 20px 10px;
		}
		.live-set-item {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			.title {
				font-size: 26rpx;
				font-weight: bold;
			}

			// 按钮
			.btn-box {
				height: 56rpx;
				line-height: 56rpx;
				padding: 0 20rpx;
				background: linear-gradient(90deg, #0f80ff, #0000ff);
				border-radius: 60px;
				display: flex;
				flex-direction: row;
				align-items: center;
				color: #ffffff;
				.btn-end {
					width: 26rpx;
					height: 26rpx;
					margin-right: 8rpx;
				}
				.btn-play {
					width: 16rpx;
					height: 20rpx;
					margin-right: 12rpx;
				}
				.btn-txt {
					font-size: 28rpx;
					color: #ffffff;
				}
			}
		}
	}
}
</style>